package com.saq691.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * 
 *
 * @datetime: 2022年11月07日 下午20:12:34
 * @author: sunaiqiang saq691@126.com
 * @version: 1.0
 */
@RestController
public class RedisController {
	private static final Logger logger = LoggerFactory.getLogger(RedisController.class);
	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	/**
	 * 
	 * @return
	 */
	@GetMapping("/sentinelCluster")
	public String masterSlave() {
		String result = HttpStatus.OK.getReasonPhrase();
		try {
			for (int i = 1; i < 1000; i++) {
				stringRedisTemplate.opsForValue().set("saq" + i, "saiqiang" + i);
				Thread.sleep(2000);
				logger.info(result + "，key：" + "saq" + i);
			}
		} catch (InterruptedException e) {
			logger.error(e.getMessage());
		}
		return result;
	}
}
